package com.biz.primus.management.order.init;

import com.biz.primus.account.service.AuthInitializeService;
import com.biz.primus.base.enums.CommonStatus;
import com.biz.primus.model.sso.auth.vo.GrantedAuthority;
import com.biz.primus.model.sso.auth.vo.MenuGroupVO;
import com.biz.primus.model.sso.auth.vo.MenuItemVO;
import com.biz.primus.model.sso.auth.vo.ResourceVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.List;

import static com.google.common.collect.Lists.newArrayList;

/**
 * Created by jun.liu on 9/19/17.
 */
@Service
public class InitManager {

    private final AuthInitializeService authInitializeService;

    @Autowired
    public InitManager(AuthInitializeService authInitializeService) {
        this.authInitializeService = authInitializeService;
    }

    @PostConstruct
    public void setup() {

        List<MenuGroupVO> menuGroups = newArrayList();
        MenuGroupVO menuGroupVO = new MenuGroupVO("MANAGEMENT_DEMO", "示例管理", "各种示例管理", "fa fa-cogs", CommonStatus.ENABLE, 999);

        /**============START===========*/
        List<MenuItemVO> menuItems = newArrayList();
        MenuItemVO adManageMenuItemVO = new MenuItemVO("MANAGEMENT_AD", "广告管理", "广告管理", "fa fa-list", "advertisement/ad/list.do", CommonStatus.ENABLE, 1);
        adManageMenuItemVO.setGrantedAuthority(new GrantedAuthority("ROLE_AD;OPT_AD_LIST"));

        List<ResourceVO> adResources = newArrayList();
        adResources.add(new ResourceVO("MANAGEMENT_AD_EDIT", "修改", "修改广告", CommonStatus.ENABLE, new GrantedAuthority("OPT_AD_EDIT"), 1));
        adResources.add(new ResourceVO("MANAGEMENT_AD_DELETE", "删除", "删除广告", CommonStatus.ENABLE, new GrantedAuthority("OPT_AD_DELETE"), 2));

        adManageMenuItemVO.setResources(adResources);
        /**============END===========*/


        /**============START===========*/
        MenuItemVO advManageMenuItemVO = new MenuItemVO("MANAGEMENT_ADV", "广告位管理", "广告位管理", "fa fa-list", "advertisement/adv/list.do", CommonStatus.ENABLE, 2);
        advManageMenuItemVO.setGrantedAuthority(new GrantedAuthority("ROLE_ADV;OPT_ADV_LIST"));

        List<ResourceVO> advResources = newArrayList();
        advResources.add(new ResourceVO("MANAGEMENT_ADV_EDIT", "修改", "修改广告位", CommonStatus.ENABLE, new GrantedAuthority("OPT_ADV_EDIT"), 3));
        advResources.add(new ResourceVO("MANAGEMENT_ADV_DELETE", "删除", "删除广告位", CommonStatus.ENABLE, new GrantedAuthority("OPT_ADV_DELETE"), 4));

        advManageMenuItemVO.setResources(advResources);
        /**============END===========*/

        /**============START 订单===========*/
        MenuItemVO orderManageMenuItemVO = new MenuItemVO("MANAGEMENT_ORD", "订单管理", "订单管理", "fa fa-list", "order.do", CommonStatus.ENABLE, 3);
        orderManageMenuItemVO.setGrantedAuthority(new GrantedAuthority("ROLE_ORD;OPT_ORD_LIST"));

        List<ResourceVO> orderResources = newArrayList();
        orderManageMenuItemVO.setResources(orderResources);
        /**============END===========*/

        /**============START 已派单===========*/
        MenuItemVO dispatchManageMenuItemVO = new MenuItemVO("MANAGEMENT_DIS", "已派单列表", "已派单列表", "fa fa-list", "dispatch.do", CommonStatus.ENABLE, 4);
        dispatchManageMenuItemVO.setGrantedAuthority(new GrantedAuthority("ROLE_DIS;OPT_DIS_LIST"));

        List<ResourceVO> dispatchResources = newArrayList();
        dispatchManageMenuItemVO.setResources(dispatchResources);
        /**============END===========*/

        /**============START 门店申请改派订单===========*/
        MenuItemVO dispatchStoreApplicationsManageMenuItemVO = new MenuItemVO("MANAGEMENT_DSA", "门店申请改派订单列表", "门店申请改派订单列表", "fa fa-list", "dispatchStoreApplications.do", CommonStatus.ENABLE, 5);
        dispatchStoreApplicationsManageMenuItemVO.setGrantedAuthority(new GrantedAuthority("ROLE_DIS;OPT_DIS_LIST"));

        List<ResourceVO> dispatchStoreApplicationsResources = newArrayList();
        dispatchStoreApplicationsManageMenuItemVO.setResources(dispatchStoreApplicationsResources);
        /**============END===========*/

        /**============START 人工分单===========*/
        MenuItemVO manualSingleManageMenuItemVO = new MenuItemVO("MANAGEMENT_MS", "人工分单列表", "人工分单列表", "fa fa-list", "manualSingle.do", CommonStatus.ENABLE, 6);
        manualSingleManageMenuItemVO.setGrantedAuthority(new GrantedAuthority("ROLE_DIS;OPT_DIS_LIST"));

        List<ResourceVO> manualSingleResources = newArrayList();
        manualSingleManageMenuItemVO.setResources(manualSingleResources);
        /**============END===========*/


        menuItems.add(adManageMenuItemVO);
        menuItems.add(advManageMenuItemVO);
        menuItems.add(orderManageMenuItemVO);
        menuItems.add(dispatchManageMenuItemVO);
        menuItems.add(dispatchStoreApplicationsManageMenuItemVO);
        menuItems.add(manualSingleManageMenuItemVO);

        menuGroupVO.setMenuItems(menuItems);
        menuGroups.add(menuGroupVO);
        authInitializeService.registerMenu(menuGroups);
    }
}
